package com.chengxiaoxiao.service.impl;

import com.chengxiaoxiao.commons.Page;
import com.chengxiaoxiao.dao.UsersDao;
import com.chengxiaoxiao.dao.impl.UsersDaoImpl;
import com.chengxiaoxiao.domain.Users;
import com.chengxiaoxiao.service.UsersService;

import java.util.List;

public class UsersServiceImpl implements UsersService {
    private UsersDao dao = new UsersDaoImpl();


    @Override
    public void add(Users users) {
        dao.add(users);
    }

    @Override
    public void update(Users users) {
        dao.update(users);
    }

    @Override
    public void delete(long id) {
        dao.delete(id);
    }

    @Override
    public List get() {
        return dao.get();
    }

    @Override
    public Users getbyId(long id) {
        return dao.getbyId(id);

    }

    @Override
    public Page getListPage(String num) {

        int pageNum = 1;
        if (null != num && !num.equals("")) {
            pageNum = Integer.parseInt(num);
        }

        int totalRecordsNum = dao.getTotalRecordsNum();
        Page page = new Page(pageNum, totalRecordsNum);
        List list = dao.getListPage(page.getStartIndex(), page.getPageSize());
        page.setRecords(list);

        return page;
    }

    @Override
    public Users login(String username, String password) {

        return dao.getUserByUsernameAndPassword(username, password);
    }

    @Override
    public Users getUserAndExtra(long id) {

        return dao.getUserAndExtra(id);

    }

    @Override
    public Page getPageLikeSNum(String num, String snum) {

        int pageNum = 1;
        if (null != num && !"".equalsIgnoreCase(num)) {
            pageNum = Integer.parseInt(num);
        }

        int totalNumber = dao.getTotalRecordsNum();

        Page page = new Page(pageNum, totalNumber);
        List list = dao.getPageLikeSNum(page.getStartIndex(), page.getPageSize(),snum);
        page.setRecords(list);

        return page;
    }

    @Override
    public Users getAllUserInfo(int ids) {

        return dao.getAllUserInfo(ids);
    }

    @Override
    public void black(int ids,String cause) {
        dao.black(ids,cause);
    }

    @Override
    public Users getUserInfoByUid(String uid) {
        return dao.getUserInfoByUid(uid);
    }
}
